package com.yogee.topseller.fragment.product.presenter;

import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.fragment.product.model.IproductModel;
import com.yogee.topseller.fragment.product.model.bean.ProductListBean;
import com.yogee.topseller.fragment.product.model.bean.ProductTypeListBean;
import com.yogee.topseller.fragment.product.model.impl.ProductModel;
import com.yogee.topseller.fragment.product.view.IproductView;

/**
* 产品的presenter
* @author hanyu
* created by 2017/6/28 9:05
*/

public class ProductPresenter {

    private IproductModel productsModel;
    private IproductView iproductView;

    public ProductPresenter(IproductView iproduct){
        this.iproductView = iproduct;
    }


    /**
     * 产品页面获取数据
     * @param total
     * @param count
     */
    public void loadProductList(String userId, String kindId,int total,int count,int sort,int type){
        productsModel = new ProductModel();
        productsModel.loadProductsList(userId,kindId,total,count,sort,type).compose(iproductView.bindRecycler()).subscribe(new BaseSubscriber<>(new HttpOnNextListener<ProductListBean>() {
            @Override
            public void onNext(ProductListBean productListBean) {
                iproductView.loadingFinished();
                iproductView.loadProductSuccess(productListBean);
            }
        }, iproductView));
        
    }

    /**
     * 获取产品类别，全部数量
     */
    public void loadProductTypeList(){
        productsModel = new ProductModel();
        productsModel.loadProductsTypeList().compose(iproductView.bindRecycler()).subscribe(new BaseSubscriber<>(new HttpOnNextListener<ProductTypeListBean>() {
            @Override
            public void onNext(ProductTypeListBean productTypeListBean) {
                iproductView.loadingFinished();
                iproductView.loadProductTypeSuccess(productTypeListBean);
            }
        }, iproductView));
    }

}
